import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;

import utils.Facet;
import utils.Layer;
import utils.Ligne;
import utils.Vertex;




public class TopmodReader {
	public ArrayList<Facet>FacetArray=new ArrayList<Facet>();


	
	public TopmodReader() throws Exception{
		  
		   //BufferedReader in = new BufferedReader(new FileReader("C:\\Documents and Settings\\Francesco\\Bureau\\PyTopMod2.223\\dodecahedron.obj"));
		   BufferedReader in = new BufferedReader(new FileReader("C:\\Documents and Settings\\moi\\Bureau\\PyTopMod2.223\\icosahedronss.stl"));
			
			String ligne = in.readLine();
			
			
			while (ligne != null) {
				StringTokenizer st=new StringTokenizer(ligne);
				System.out.println(ligne);
				if(st.nextToken().equals("facet")){
					ligne=in.readLine(); 
					int indexVertex[]=new int[3];
					for(int i=0;i<3;i++){
					ligne=in.readLine(); 
					st=new StringTokenizer(ligne);
					st.nextToken(); 
					double x=Double.parseDouble(st.nextToken());
					double y=Double.parseDouble(st.nextToken()); 
					double z=Double.parseDouble(st.nextToken()); 
					if(Vertex.dejavu(x, y, z)==-1){
						Vertex v=new Vertex(x,y,z);
						indexVertex[i]=v.getIndex(); 
					}
					else indexVertex[i]=Vertex.dejavu(x, y, z); 
					}
					Facet fc=new Facet(indexVertex[0],indexVertex[1],indexVertex[2]); 
					System.out.println(fc);
					FacetArray.add(fc);
				}
				
				ligne = in.readLine();
			}
			in.close();
			
		
	}
	public static void main(String[] args) throws Exception{
		TopmodReader hh=new TopmodReader();
		
		PrintStream output=new PrintStream("outdodec.txt");
		
		System.out.println("****************");
		output.println("mesh2{"); 
		output.println("vertex_vectors {"); 
		output.println(Vertex.dejaVU.size()+","); 
		for(Vertex v : Vertex.dejaVU)
			output.println(v+",");
		output.println("}"); 
		output.println("face_indices {"); 
		output.println(hh.FacetArray.size()+","); 
			
		for(Facet f:hh.FacetArray)
			output.println(f+",");
		output.println("}\n }"); 
	}

}
